import {delay,call,put,all,takeEvery,takeLatest,take} from 'redux-saga/effects';
// 导入actions
import {get_message,get_message_async} from './actions';
import {GET_MESSAGE_ASYNC} from './action-types';


// root saga
function* rootSaga(){
    // 通过all触发其他saga异步处理函数
    yield all([watchSaga()]);
}  

// watcher saga
function* watchSaga(){
    yield takeEvery(GET_MESSAGE_ASYNC,getList);   
}

// worker saga: 请求远程数据
function* getList(){
    const request=yield call(fetch,'https://cnodejs.org/api/v1/topics');
    const {data}=yield request.json();
     // 通过put触发对应的action
     yield put(get_message(data));
}

export default rootSaga;